﻿using System;
using XQ.Framework.core;
using XQ.WeChatOfficialAccount.DAL;
using XQ.WeChatOfficialAccount.DAL.DAL;

namespace XQ.WeChatOfficialAccount.BLL.Account
{
    public class LoginBll
    {
        private static readonly LoginBll instance = new LoginBll();

        public static LoginBll Instance { get { return instance; } }

        public Sys_Users GetLoginResult(string name, string pass)
        {
            Sys_Users user = null;
            using (UserDal dal = new UserDal())
            {
                string md5pass = SecureHelper.getMD5(pass);
                try
                {
                    user = dal.FindModel(x => x.UserName == name && x.Password == md5pass);

                }
                catch (Exception e)
                {
                    
                    throw e;
                }
            }
            return user;
        }

        /// <summary>
        /// 根据ID和密码获取匹配用户
        /// </summary>
        /// <param name="id"></param>
        /// <param name="pass"></param>
        /// <returns></returns>
        public Sys_Users GetUserByIDAndPassword(int id, string pass)
        {
            Sys_Users user = null;
            using (UserDal dal = new UserDal())
            {
                string md5pass = SecureHelper.getMD5(pass);
                try
                {
                    user = dal.FindModel(x => x.id == id && x.Password == md5pass);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            return user;
        }

    }
}
